using System.Collections;
using UnityEngine;

public class PauseWindow : BaseWindow
{
	public static PauseWindow instance;

	public GameObject pause;

	public GameObject pauseSettings;

	private ControlsPositionsSaver _controlsPositionsSaver;

	private Coroutine _controlSettings;

	private Coroutine _settings;

	private IEnumerator LoadingSettingsController()
	{
		if (_controlsPositionsSaver == null)
		{
			LoadingPanel.instance.ShowLoadingPanel(true);
			ResourceRequest controller = Resources.LoadAsync("Prefabs/Lobby/PanelSettingsControl");
			yield return controller;
			GameObject tmp = Object.Instantiate(controller.asset as GameObject);
			tmp.transform.parent = base.transform.parent;
			tmp.transform.localScale = Vector3.one;
			_controlsPositionsSaver = base.transform.parent.GetComponentsInChildren<ControlsPositionsSaver>(true)[0];
			LoadingPanel.instance.ShowLoadingPanel(false);
		}
		_controlsPositionsSaver.ShowThis();
		_controlSettings = null;
	}

	private void Awake()
	{
		instance = this;
	}

	private void OnDestroy()
	{
		instance = null;
		if (IsInvoking("sortGrid"))
		{
			CancelInvoke("sortGrid");
		}
	}

	private void OnEnable()
	{
	}

	private void OnDisable()
	{
	}

	public override void OnPreShow(object userData)
	{
		pause.SetActive(true);
		if (pauseSettings != null)
		{
			pauseSettings.SetActive(false);
		}
	}

	public override void OnHide()
	{
		Invoke("PlayMainMusic", 0.2f);
	}

	private void PlayMainMusic()
	{
	}

	public void ShowControlSettings()
	{
		if (_controlSettings == null)
		{
			_controlSettings = StartCoroutine(LoadingSettingsController());
		}
	}

	public void ShowSettings()
	{
		if (_settings == null)
		{
			_settings = StartCoroutine(ShowSettingsAfterWait());
		}
	}

	public IEnumerator ShowSettingsAfterWait()
	{
		if (pauseSettings == null)
		{
			LoadingPanel.instance.ShowLoadingPanel(true);
			ResourceRequest pause = Resources.LoadAsync("Prefabs/Level1/settings");
			yield return pause;
			pauseSettings = Object.Instantiate(pause.asset as GameObject);
			pauseSettings.transform.parent = base.transform;
			pauseSettings.transform.localScale = Vector3.one;
			LoadingPanel.instance.ShowLoadingPanel(false);
		}
		pauseSettings.SetActive(true);
		this.pause.SetActive(false);
		_settings = null;
	}

	public void ShowPauseMenu()
	{
		pause.SetActive(true);
		if (pauseSettings != null)
		{
			pauseSettings.SetActive(false);
		}
	}
}
